<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class User extends MY_Controller
{
	public function __construct()
	{
		parent::__construct();
		$this->load->model('User_model', 'user');
		$login_status  = $this->check_login_status();
        if (empty($login_status)){
        	$this->load->view('/');
        }
	}
    public function index()
    {

        $this->load->view('/user/account');
    }
    public function account(){
    	$_SESSION['sidebar'] = "account";  
        $departmentName = $this->user->getDepartmentInfo($_SESSION['userInfo']['departmentid']);
        $userInfo = $this->user->get_userinfo($_SESSION['userInfo']['AccountID']);
    	$data = ['departmentName'=>$departmentName,'userInfo'=>$userInfo];
    	$this->load->view('/user/account',$data);
    }

    /**
     * 重置密码
     */
    public function reset_password()
    {
    	$res = 0;
        $password = $this->input->post('password', TRUE);
        $zhuanye = $this->input->post("zhuanye",true) ? $this->input->post("zhuanye",true) : '';
        $zhicheng = $this->input->post("zhicheng",true) ? $this->input->post("zhicheng",true) : '';
        $sex = $this->input->post("sex",true) ? $this->input->post("sex",true) : 1;
        $qq = $this->input->post("qq",true) ? $this->input->post("qq",true) : '';
        $mobile = $this->input->post("mobile",true) ? $this->input->post("mobile",true) : '';
        if(!empty($password) && !preg_match("/^[a-z0-9_]*$/i",$password))
        {
            echo json_encode(array('code'=>-3,'message'=>'密码只能是字母数字或下划线格式的字符!'));
            return;
        }
        if(!empty($password) && !preg_match("/^[a-z0-9_]{6,16}$/i",$password))
        {
            echo json_encode(array('code'=>-3,'message'=>'密码请设置为6-16个字符!'));
            return;
        }
        $data = array();
        $data['password']       =   md6($password);
        $data['zhuanye']       =   $zhuanye;
        $data['zhicheng']       =   $zhicheng;
        $data['qq']             =   $qq;
        $data['mobile']       =   $mobile;

        $res = $this->user->editUser($_SESSION['userInfo']['AccountID'], $data);
  /*      if (!empty($password)) {
            $res = $this->user->reset_password($_SESSION['userInfo']['AccountID'], $password);
        }*/
        echo json_encode(array('code'=>$res));

    }
	
}
/* End of file login.php */
/* Location: ./application/controllers/luckydog/login.php */
